package com.youlai.boot.system.service.order;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.youlai.boot.common.exception.BusinessException;
import com.youlai.boot.system.model.entity.LpsWl;
import com.youlai.boot.system.model.vo.CommonOrderVO;
import com.youlai.boot.system.model.vo.LpsOrderXianVO;
import com.youlai.boot.util.MapUtils;
import com.youlai.boot.util.NumberUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
@Slf4j
public class XianOrderHandle {

    public final static String AN_ZHUANG = "安装所在国家或地区";
    public final static String CAR_SAFETY_GEAR_TYPE = "CAR_SAFETY_GEAR_TYPE";
    public final static String HK = "HK";
    public final static String BK = "BK";
    public final static String TK = "TK";
    public final static String HK_1 = "轿厢高度 HK";
    public final static String BK_1 = "轿厢宽度 BK";
    public final static String TK_1 = "轿厢深度 TK";
    public final static String GRP_ALARM_TYPE = "GRP_ALARM_TYPE";
    public final static String MARKET_CLUSTER = "MARKET_CLUSTER";
    public final static String SCK_LMS_TYPE = "SCK_LMS_TYPE";
    public final static String DXLX = "电缆线类型";

    public final static String PM_ID = "PM物料ID选择";
    public final static String WL_57647111 = "57647111";
    public final static String WL_57647112 = "57647112";
    public final static String WL_57670329 = "57670329";
    public final static String WL_C57865502_001 = "C57865502-001";
    public final static String WL_57671686 = "57671686";
    public final static String WL_59385850 = "59385850";
    public final static String WL_59385851 = "59385851";
    public final static String WL_57860994 = "57860994";
    public final static String WL_59351848 = "59351848";

    public final static List<String> WL_LIST = CollectionUtil.newArrayList(WL_57670329, WL_57671686, WL_59385850, WL_59385851, WL_59351848);

    /**
     * @param objList
     * @param lpsWlMap
     * @return
     */
    public List<LpsOrderXianVO> handle(List<CommonOrderVO> objList, Map<String, LpsWl> lpsWlMap) {
        if (CollectionUtil.isEmpty(objList)) {
            return CollectionUtil.newArrayList();
        }
        List<LpsOrderXianVO> list = new ArrayList<>();
        objList.stream().forEach(item -> {
            LpsOrderXianVO order = new LpsOrderXianVO();
            BeanUtils.copyProperties(item, order);
            if (Objects.nonNull(lpsWlMap.get(order.getWl()))) {
                order.setBz(lpsWlMap.get(order.getWl()).getRemark());
            }
            Map<String, String> featureMap = MapUtils.getFeatureMap(item.getTz());
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));

            String wlNo = order.getWl();
            long rowId = IdUtil.getSnowflakeNextId();
            order.setRowId(rowId);
            switch (wlNo) {
                case WL_57647111:
                    WL_57647111(featureMap, order);
                    break;
                case WL_57647112:
                    WL_57647112(featureMap, order);
                    break;
                case WL_57670329:
                    WL_57670329_PM_59385852(featureMap, item, list, rowId);
                    WL_57670329_PM_59385857(featureMap, item, list, rowId);
                    WL_57670329_PM_59385856(featureMap, item, list, rowId);
                    WL_57670329_PM_59385854(featureMap, item, list, rowId);
                    break;
                case WL_C57865502_001:
                    WL_C57865502_001(featureMap, order);
                    break;
                case WL_57860994:
                    WL_57860994(featureMap, order);
                    break;
                case WL_57671686:
                    WL_57671686_PM_59385852(featureMap, item, list, rowId);
                    WL_57671686_PM_59385857(featureMap, item, list, rowId);
                    WL_57671686_PM_59385856(featureMap, item, list, rowId);
                    WL_57671686_PM_59385853(featureMap, item, list, rowId);
                    break;
                case WL_59385850:
                    WL_59385850_PM_59385852(item, list, rowId);
                    WL_59385850_PM_59385857(item, list, rowId);
                    WL_59385850_PM_59385856(item, list, rowId);
                    WL_59385850_PM_59385853(item, list, rowId);
                    break;
                case WL_59385851:
                    WL_59385851_PM_59385852(item, list, rowId);
                    WL_59385851_PM_59385857(item, list, rowId);
                    WL_59385851_PM_59385856(item, list, rowId);
                    WL_59385851_PM_59385854(item, list, rowId);
                    break;
                case WL_59351848:
                    WL_59351848(featureMap, item, list, rowId);
                    break;
                default:
                    log.error("【新产品 线】解析到未知的物料{}", wlNo);
            }
            if (!WL_LIST.contains(wlNo)) {
                order.setId(IdUtil.getSnowflakeNextId());
                list.add(order);
            }
        });
        return list;
    }

    /**
     * 存在子件 但是无需处理
     *
     * @param item
     * @param list
     */
    public void WL_59351848(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
        order.setZj("59351850");
        order.setRowId(rowId);
        list.add(order);

        LpsOrderXianVO order1 = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order1);
        order1.setId(IdUtil.getSnowflakeNextId());
        //order1.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
        order1.setZj("59351852");
        order1.setRowId(rowId);
        list.add(order1);

        LpsOrderXianVO order2 = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order2);
        order2.setId(IdUtil.getSnowflakeNextId());
        //order2.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
        order2.setZj("59351854");
        order2.setRowId(rowId);
        list.add(order2);

        LpsOrderXianVO order3 = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order3);
        order3.setId(IdUtil.getSnowflakeNextId());
        //order3.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
        order3.setZj("59351856");
        order3.setRowId(rowId);
        list.add(order3);
    }

    private void WL_59385851_PM_59385854(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setRowId(rowId);
        order.setZj("59385854");
        try {
            // 正则表达式：提取 BK、TK、HK 和 电缆类型完整信息
            Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?电缆类型：\\s*([^$]+)");
            Matcher matcher = pattern.matcher(item.getLongText());

            if (matcher.find()) {
                String bkValue = matcher.group(1);
                String tkValue = matcher.group(2);
                String hkValue = matcher.group(3);
                String dxlx = matcher.group(4).trim(); // 去除前后空格

                order.setBk(NumberUtils.extractValueStr(bkValue));
                order.setTk(NumberUtils.extractValueStr(tkValue));
                order.setHk(NumberUtils.extractValueStr(hkValue));

                order.setDxlx(dxlx);

                double hk = parseValue(order.getHk());
                double bk = parseValue(order.getBk());
                double tk = parseValue(order.getTk());

                double dxjsz = hk + tk / 2 + bk + 900;
                String dxzd = dxjsz <= 6000 ? "6000" : "7500";
                order.setBz("当 HK+TK/2+BK+900 <= 6000 时，电线选择长度6000mm，根据ID59348089\n" +
                        "当 HK+TK/2+BK+900 > 6000 时，电线选择长度7500mm，根据ID59348088");
                order.setDxzd(dxzd);
                order.setDxjsz(dxjsz + "");
            } else {
                order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
            }
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
        }
        list.add(order);
    }

    private void WL_59385851_PM_59385856(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385856");
        order.setRowId(rowId);
        try {
            order.setBz("需要调拨件，数量1PC");
        } catch (Exception e) {
            order.setBz("错误:解析错误");
        }
        list.add(order);
    }


    private void WL_59385851_PM_59385857(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385857");
        order.setRowId(rowId);
        try {
            // 正则表达式：提取 BK、TK、HK 和 电缆类型完整信息
            Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?");
            Matcher matcher = pattern.matcher(item.getLongText());

            if (matcher.find()) {
                String bkValue = matcher.group(1);
                String tkValue = matcher.group(2);
                String hkValue = matcher.group(3);

                order.setBk(NumberUtils.extractValueStr(bkValue));
                order.setTk(NumberUtils.extractValueStr(tkValue));
                order.setHk(NumberUtils.extractValueStr(hkValue));


                double hk = parseValue(order.getHk());
                double bk = parseValue(order.getBk());
                double tk = parseValue(order.getTk());

                double dxjsz = hk + tk / 2 + bk + 1500;
                String dxzd = "2500";
                order.setBz("TK/2+BK+HK+1500<= 6000 时,此件不提供；\n" +
                        "TK/2+BK+HK+1500>6000 时,此件提供，数量1PC；");
                order.setDxzd(dxzd);
                order.setDxjsz(dxjsz + "");
                order.setSl(dxjsz <= 6000 ? "0" : order.getSl());
            } else {
                order.setBz("错误:解析 HK/BK/TK 时发生 项目文本无法解析");
            }
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 项目文本无法解析");
        }
        list.add(order);
    }

    private void WL_59385851_PM_59385852(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385852");
        order.setRowId(rowId);
        try {
            // 正则表达式：提取 BK、TK、HK 和 电缆类型完整信息
            Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?电缆类型：\\s*([^$]+)");
            Matcher matcher = pattern.matcher(item.getLongText());

            if (matcher.find()) {
                String bkValue = matcher.group(1);
                String tkValue = matcher.group(2);
                String hkValue = matcher.group(3);
                String dxlx = matcher.group(4).trim(); // 去除前后空格

                order.setBk(NumberUtils.extractValueStr(bkValue));
                order.setTk(NumberUtils.extractValueStr(tkValue));
                order.setHk(NumberUtils.extractValueStr(hkValue));

                order.setDxlx(dxlx);

                double hk = parseValue(order.getHk());
                double bk = parseValue(order.getBk());
                double tk = parseValue(order.getTk());

                double dxjsz = hk + tk / 2 + bk + 600;
                String dxzd = dxjsz <= 4800 ? "4800" : "5900";
                order.setBz("当 HK+TK/2+BK+600 <= 4800 时,电线选择长度4800mm \n" +
                        "当 HK+TK/2+BK+600 > 4800 时,电线选择长度5900mm");
                order.setDxzd(dxzd);
                order.setDxjsz(dxjsz + "");
            } else {
                order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
            }
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
        }
        list.add(order);
    }

    private void WL_59385850_PM_59385853(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385853");
        order.setRowId(rowId);
        try {
            // 正则表达式：提取 BK、TK、HK 和 电缆类型完整信息
            Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?电缆类型：\\s*([^$]+)");
            Matcher matcher = pattern.matcher(item.getLongText());

            if (matcher.find()) {
                String bkValue = matcher.group(1);
                String tkValue = matcher.group(2);
                String hkValue = matcher.group(3);
                String dxlx = matcher.group(4).trim(); // 去除前后空格

                order.setBk(NumberUtils.extractValueStr(bkValue));
                order.setTk(NumberUtils.extractValueStr(tkValue));
                order.setHk(NumberUtils.extractValueStr(hkValue));

                order.setDxlx(dxlx);

                double hk = parseValue(order.getHk());
                double bk = parseValue(order.getBk());
                double tk = parseValue(order.getTk());

                double dxjsz = hk + tk / 2 + bk + 900;
                String dxzd = dxjsz <= 6000 ? "6000" : "7500";
                order.setBz("当 HK+TK/2+BK+900 <= 6000 时，电线选择长度6000mm，根据ID59348089\n" +
                        "当 HK+TK/2+BK+900 ＞ 6000 时，电线选择长度7500mm，根据ID59348088");
                order.setDxzd(dxzd);
                order.setDxjsz(dxjsz + "");
            } else {
                order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
            }
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
        }
        list.add(order);
    }

    private void WL_59385850_PM_59385856(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385856");
        order.setRowId(rowId);
        try {
            order.setBz("需要调拨件，数量1PC");
        } catch (Exception e) {
            order.setBz("错误:解析错误");
        }
        list.add(order);
    }

    private void WL_59385850_PM_59385857(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385857");
        order.setRowId(rowId);
        try {
            // 正则表达式：提取 BK、TK、HK 和 电缆类型完整信息
            Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?电缆类型：\\s*([^$]+)");
            Matcher matcher = pattern.matcher(item.getLongText());

            if (matcher.find()) {
                String bkValue = matcher.group(1);
                String tkValue = matcher.group(2);
                String hkValue = matcher.group(3);
                //String dxlx = matcher.group(4).trim(); // 去除前后空格

                order.setBk(NumberUtils.extractValueStr(bkValue));
                order.setTk(NumberUtils.extractValueStr(tkValue));
                order.setHk(NumberUtils.extractValueStr(hkValue));

                //order.setDxlx(dxlx);

                double hk = parseValue(order.getHk());
                double bk = parseValue(order.getBk());
                double tk = parseValue(order.getTk());

                double dxjsz = hk + tk / 2 + bk + 1500;
                String dxzd = "2500";
                order.setBz("TK/2+BK+HK+1500<= 6000 时,此件不提供；\n" +
                        "TK/2+BK+HK+1500>6000 时,此件提供，数量1PC；");

                order.setDxzd(dxzd);
                order.setDxjsz(dxjsz + "");
                order.setSl(dxjsz <= 6000 ? "0" : order.getSl());
            } else {
                order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
            }
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
        }
        list.add(order);
    }

    private void WL_59385850_PM_59385852(CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385852");
        order.setRowId(rowId);
        try {
            // 正则表达式：提取 BK、TK、HK 和 电缆类型完整信息
            //Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?");
            Pattern pattern = Pattern.compile("BK=\\s*(\\d+)\\s*TK=\\s*(\\d+)\\s*HK=\\s*(\\d+).*?电缆类型：\\s*([^$]+)");
            Matcher matcher = pattern.matcher(item.getLongText());

            if (matcher.find()) {
                String bkValue = matcher.group(1);
                String tkValue = matcher.group(2);
                String hkValue = matcher.group(3);
                String dxlx = matcher.group(4).trim(); // 去除前后空格

                order.setBk(NumberUtils.extractValueStr(bkValue));
                order.setTk(NumberUtils.extractValueStr(tkValue));
                order.setHk(NumberUtils.extractValueStr(hkValue));

                order.setDxlx(dxlx);

                double hk = parseValue(order.getHk());
                double bk = parseValue(order.getBk());
                double tk = parseValue(order.getTk());

                double dxjsz = hk + tk / 2 + bk + 600;
                String dxzd = dxjsz <= 4800 ? "4800" : "5900";
                order.setBz("当 HK+TK/2+BK+600 <= 4800 时,电线选择长度4800mm \n" +
                        "当 HK+TK/2+BK+600 > 4800 时,电线选择长度5900mm");

                order.setDxzd(dxzd);
                order.setDxjsz(dxjsz + "");
            } else {
                order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
            }
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK/电缆类型 时发生 项目文本无法解析");
        }
        list.add(order);
    }

    private void WL_57671686_PM_59385853(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385853");
        order.setRowId(rowId);
        try {
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK_1, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK_1, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK_1, "")));
            order.setDxlx(featureMap.getOrDefault(DXLX, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk + 900;
            String dxzd = dxjsz <= 6000 ? "6000" : "7500";
            order.setBz("当 HK+TK/2+BK+900 <= 6000 时，电线选择长度6000mm，根据ID59348089\n" +
                    "当 HK+TK/2+BK+900 > 6000 时，电线选择长度7500mm，根据ID59348088");

            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换，物料号");
        }
        list.add(order);
    }

    private void WL_57671686_PM_59385856(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385856");
        order.setRowId(rowId);
        try {
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
            order.setSckLmsType(featureMap.getOrDefault(XianOrderHandle.SCK_LMS_TYPE, ""));

            order.setBz("SCK_LMS_TYPE=1 时，需要调拨件，数量1 pc\n" +
                    "SCK_LMS_TYPE=2 时, 无调拨件，");
            order.setSl(order.getSckLmsType().equals("2") ? "0" : order.getSl());
        } catch (Exception e) {
            order.setBz("错误:解析错误");
        }
        list.add(order);
    }

    private void WL_57671686_PM_59385857(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385857");
        order.setRowId(rowId);
        try {
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK_1, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK_1, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK_1, "")));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk + 1500;
            String dxzd = "2500";
            order.setBz("TK/2+BK+HK+1500<= 6000 时,此件不提供；\n" +
                    "TK/2+BK+HK+1500＞6000 时,此件提供；");

            order.setSl(dxjsz <= 6000 ? "0" : order.getSl());
            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换");
        }
        list.add(order);
    }

    private void WL_57671686_PM_59385852(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385852");
        order.setRowId(rowId);
        try {
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK_1, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK_1, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK_1, "")));
            order.setDxlx(featureMap.getOrDefault(DXLX, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk + 600;
            String dxzd = dxjsz <= 4800 ? "4800" : "5900";
            order.setBz("当 HK+TK/2+BK+600 <= 4800 时,电线选择长度4800mm \n" +
                    "当 HK+TK/2+BK+600 > 4800 时,电线选择长度5900mm");

            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换");
        }
        list.add(order);
    }

    private void WL_57860994(Map<String, String> featureMap, LpsOrderXianVO order) {
        order.setGrpAlarmType(featureMap.getOrDefault(XianOrderHandle.GRP_ALARM_TYPE, ""));
        if (StrUtil.isNotBlank(order.getGrpAlarmType())){
            if (order.getGrpAlarmType().equals("GSP_TAI_5_5")){
                order.setBz("当 GRP_ALARM_TYPE 等于 GSP_TAI_5_5 时,不提供 6.8.9号子件。");
            }else {
                order.setBz("当 GRP_ALARM_TYPE 不等于GSP_TAI_5_5 时,提供 6.8.9 号子件,数量各1件。");
            }
        }else {
            order.setBz("错误:GRP_ALARM_TYPE提取不到数据");
        }
    }

    private void WL_C57865502_001(Map<String, String> featureMap, LpsOrderXianVO order) {
        order.setAzszgjhdq(featureMap.getOrDefault(XianOrderHandle.AN_ZHUANG, ""));
    }

    private void WL_57670329_PM_59385854(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385854");
        order.setRowId(rowId);
        try {
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK, "")));
            order.setDxlx(featureMap.getOrDefault(DXLX, ""));
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk + 900;
            String dxzd = dxjsz <= 6000 ? "6000" : "7500";
            order.setBz("当 HK+TK/2+BK+900 <= 6000 时，电线选择长度6000mm，根据ID59348089\n" +
                    "当 HK+TK/2+BK+900 > 6000 时，电线选择长度7500mm，根据ID59348088");

            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换");
        }
        list.add(order);
    }

    private void WL_57670329_PM_59385856(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385856");
        order.setRowId(rowId);
        try {
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));
            order.setSckLmsType(featureMap.getOrDefault(XianOrderHandle.SCK_LMS_TYPE, ""));
            order.setMarketCluster(featureMap.getOrDefault(XianOrderHandle.MARKET_CLUSTER, ""));

            order.setBz("只有当MARKET_CLUSTER=1，LMS_TYPE=2，无调拨件。\n" +
                    "其余参数（其中当MARKET_CLUSTER=2时，LMS_TYPE无参数），需要调拨件，数量1PC。");
            if (StrUtil.isNotBlank(order.getMarketCluster()) && StrUtil.isNotBlank(order.getSckLmsType())) {
                if (order.getMarketCluster().equals("1") && order.getSckLmsType().equals("2")) {
                    order.setSl("0");
                }
                if (order.getMarketCluster().equals("2")) {
                    order.setSckLmsType(null);
                }
            }
        } catch (Exception e) {
            order.setBz("错误:解析错误");
        }
        list.add(order);
    }

    private void WL_57670329_PM_59385857(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385857");
        order.setRowId(rowId);
        try {
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK, "")));
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = tk / 2 + bk + hk + 1500;
            String dxzd = "2500";
            order.setSl(dxjsz <= 6000 ? "0" : order.getSl());
            order.setBz("TK/2+BK+HK+1500<= 6000 时,此件不提供；\n" +
                    "TK/2+BK+HK+1500>6000 时,此件提供，数量1PC；");

            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换");
        }
        list.add(order);
    }


    private void WL_57670329_PM_59385852(Map<String, String> featureMap, CommonOrderVO item, List<LpsOrderXianVO> list, long rowId) {
        LpsOrderXianVO order = new LpsOrderXianVO();
        BeanUtils.copyProperties(item, order);
        order.setId(IdUtil.getSnowflakeNextId());
        order.setZj("59385852");
        order.setRowId(rowId);
        try {
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK, "")));
            order.setDxlx(featureMap.getOrDefault(DXLX, ""));
            //order.setAzszgjhdq(featureMap.getOrDefault(AN_ZHUANG, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk + 600;
            String dxzd = dxjsz <= 4800 ? "4800" : "5900";
            order.setBz("当 HK+TK/2+BK+600 <= 4800 时,电线选择长度4800mm \n" +
                    "当 HK+TK/2+BK+600 > 4800 时,电线选择长度5900mm");

            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换");
        }
        list.add(order);
    }

    private void WL_57647112(Map<String, String> featureMap, LpsOrderXianVO order) {
        try {
            order.setCarSafetyGearType(featureMap.getOrDefault(XianOrderHandle.CAR_SAFETY_GEAR_TYPE, ""));
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK, "")));
            order.setDxlx(featureMap.getOrDefault(DXLX, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk + 900;
            String dxzd = dxjsz <= 6000 ? "6000" : "7500";

            Double carValue = NumberUtils.getDouble(order.getCarSafetyGearType());
            if (Objects.nonNull(carValue)) {
                order.setKgsl(carValue == 7 ? "2" : "1");
                //order.setSl(order.getKgsl());
                order.setDxsl(order.getKgsl());
            }

            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK/CAR_SAFETY_GEAR_TYPE 时发生 数字无法转换");
        }
    }


    private void WL_57647111(Map<String, String> featureMap, LpsOrderXianVO order) {
        try {
            order.setBk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.BK, "")));
            order.setTk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.TK, "")));
            order.setHk(NumberUtils.extractValueStr(featureMap.getOrDefault(XianOrderHandle.HK, "")));
            order.setDxlx(featureMap.getOrDefault(DXLX, ""));

            double hk = parseValue(order.getHk());
            double bk = parseValue(order.getBk());
            double tk = parseValue(order.getTk());

            double dxjsz = hk + tk / 2 + bk / 2 + 600;
            String dxzd = dxjsz <= 4800 ? "4800" : "5900";
            order.setDxzd(dxzd);
            order.setDxjsz(dxjsz + "");
        } catch (Exception e) {
            order.setBz("错误:解析 HK/BK/TK 时发生 数字无法转换");
        }
    }


    /**
     * @param value
     * @return
     */
    private double parseValue(String value) {
        return Double.parseDouble(value);
    }

    /**
     * 有些物料存在子件
     *
     * @param order
     * @return
     */
    public String getWlNo(LpsOrderXianVO order, Map<String, String> featureMap) {
        switch (order.getWl()) {
            case WL_57670329, WL_57671686, WL_59385850, WL_59385851:
                order.setZj(featureMap.getOrDefault(XianOrderHandle.PM_ID, ""));
                return order.getWl() + "|" + order.getZj();
            default:
                return order.getWl();
        }
    }

}
